package com.zr.controller.driverclient;


import com.zr.service.driverclient.UploadService;
import com.zr.utils.AjaxResult;
import com.zr.vo.dispatch.DispatchAbnormalRecord;
import com.zr.vo.order.OrderForm;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.*;


@RestController
@RequestMapping("/upload")
public class UploadController {
    @Resource
    private UploadService uploadService;

    /**
     * 保存订单的回执单图片
     *
     * @param file
     * @param id
     * @param orderId
     * @return
     * @throws IOException
     */
    @PostMapping("/save")
    public AjaxResult savePicture(@RequestParam("file") MultipartFile file, @RequestParam("id") Integer id, @RequestParam("orderId") String orderId) throws IOException {

        return AjaxResult.success(200, "保存成功", uploadService.upload(file, id, orderId));
    }

    /**
     * 保存异常的图片
     *
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/saveAbnormal")
    public AjaxResult saveAbnormal(@RequestParam("file") MultipartFile file) throws IOException {

        return AjaxResult.success(200, "保存成功", uploadService.saveAbnormal(file));
    }

    /**
     * 获取订单图片
     *
     * @param orderForm
     * @return
     */
    @PostMapping("/getImg")
    public AjaxResult getImg(@RequestBody OrderForm orderForm) {
        String name = orderForm.getFinishImg();
        return AjaxResult.success(200, "查询成功", uploadService.getImg(name));
    }

    /**
     * 获取异常订单图片
     *
     * @param dispatchAbnormalRecord
     * @return
     */
    @PostMapping("/getAbnImg")
    public AjaxResult getAbnImg(@RequestBody DispatchAbnormalRecord dispatchAbnormalRecord) {
        String aid = dispatchAbnormalRecord.getAid();
        return AjaxResult.success(200, "查询成功", uploadService.getAbnImg(aid));
    }
}